package com.example.makotoshoda.myvibe;

import android.app.Notification;
import android.app.NotificationManager;
import android.os.Vibrator;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {

    private Vibrator mVib;
    private Notification mNotify;
    private NotificationManager mNotificationManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mVib = (Vibrator) getSystemService(VIBRATOR_SERVICE);

        View.OnClickListener click_listener1 = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case R.id.start:
                        mVib.vibrate(10000);
                        Toast.makeText(MainActivity.this, "vibe", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.stop:
                        mVib.cancel();
                        break;
                }
            }
        };
        Button btn = (Button) findViewById(R.id.start);
        btn.setOnClickListener(click_listener1);
        btn = (Button)findViewById(R.id.stop);
        btn.setOnClickListener(click_listener1);

        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mNotify = new Notification();
        mNotify.vibrate = new long[] {10000};

        View.OnClickListener click_listener2 = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case R.id.start2:
                        mNotificationManager.notify(R.string.app_name, mNotify);
                        break;
                    case R.id.stop2:
                        break;
                }
            }
        };
        btn = (Button)findViewById(R.id.start2);
        btn.setOnClickListener(click_listener2);
        btn = (Button)findViewById(R.id.stop2);
        btn.setOnClickListener(click_listener2);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
